home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
src
/
fig05_12.jar
/
Ch05
/
Fig05_12
/
Fig05_12.cpp
next >
Wrap
C/C++ Source or Header
|
1997-10-14
|
401b
|
24 lines
// Fig. 5.12: fig05_12.cpp
// Attempting to modify data through a
// non-constant pointer to constant data.
#include <iostream.h>
void f( const int * );
int main()
{
int y;
f( &y ); // f attempts illegal modification
return 0;
}
// In f, xPtr is a pointer to an integer constant
void f( const int *xPtr )
{
*xPtr = 100; // cannot modify a const object
}